package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import com.qf.service.DtsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DtsBrandServiceImpl implements DtsBrandService {
    @Autowired
    DtsBrandMapper brandMapper;

    @Override
    public List<Integer> findBreadAdminId(Integer id) {
        LambdaQueryWrapper<DtsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsBrand::getAdminId, id);
        wrapper.eq(DtsBrand::getDeleted, false);

        wrapper.select(DtsBrand::getId);

        List<DtsBrand> dtsBrands = brandMapper.selectList(wrapper);
        List<Integer> brands = dtsBrands.stream().map((brand) -> {
            return brand.getId();
        }).collect(Collectors.toList());
        return brands;
    }

    @Override
    public List<Map<String, Object>> findBrandList(List<Integer> brandIds) {
        LambdaQueryWrapper<DtsBrand> wrapper = new LambdaQueryWrapper<>();
        if (brandIds != null && brandIds.size() > 0) {
            wrapper.in(DtsBrand::getId, brandIds);
        }
        List<DtsBrand> brandList = brandMapper.selectList(wrapper);
        List<Map<String, Object>> data = brandList.stream().map((brand) -> {
            Map<String, Object> map = new HashMap<>();
            map.put("value", brand.getId());
            map.put("label", brand.getName());
            return map;
        }).collect(Collectors.toList());

        return data;
    }

    @Override
    public DtsBrand selectById(Integer brandId) {

        DtsBrand dtsBrand = brandMapper.selectById(brandId);
        return dtsBrand;
    }
}
